package cn.milolab.djback.conf;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author milowang
 */
@Getter
public class DjException extends RuntimeException {
    private final DjExceptionStatus status;

    private DjException(DjExceptionStatus status, String msg) {
        super(msg);
        this.status = status;
    }

    public static DjException requestLogicError(String msg) {
        return new DjException(DjExceptionStatus.REQUEST_LOGIC_ERROR, msg);
    }

    public static DjException unauthenticated(String msg) {
        return new DjException(DjExceptionStatus.UNAUTHENTICATED, msg);
    }

    public static DjException accessDenied(String msg) {
        return new DjException(DjExceptionStatus.ACCESS_DENIED, msg);
    }

    public static DjException internalServerError(String msg) {
        return new DjException(DjExceptionStatus.INTERNAL_SERVER_ERROR, msg);
    }

    @AllArgsConstructor
    @Getter
    public enum DjExceptionStatus {

        // 请求逻辑错误
        REQUEST_LOGIC_ERROR(400),

        // 未登录
        UNAUTHENTICATED(401),

        // 权限不足
        ACCESS_DENIED(403),

        // 服务器内部错误
        INTERNAL_SERVER_ERROR(500);

        private final Integer code;
    }
}
